package com.hbue.springboot.pojo;

import com.hbue.springboot.utils.ResultCode;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 功能：
 * 日期：2025/1/12 15:48
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Result<T> {
    private Integer code;
    private String msg;
    private T data;

    public Result(ResultCode resultCode) {
        this.code = resultCode.getCode();
        this.msg = resultCode.getMsg();
    }

    public Result(ResultCode resultCode, T data) {
        this.code = resultCode.getCode();
        this.msg = resultCode.getMsg();
        this.data = data;
    }

    public Result(String msg) {
        this.msg = msg;
    }

    public static Result<String> success() {
        return new Result<String>(ResultCode.SUCCESS);
    }

    public static <T> Result<T> success(T data) {
        return new Result<T>(ResultCode.SUCCESS, data);
    }

    public static Result<String> error() {
        return new Result<>(ResultCode.FAIL);
    }

    public static  Result<String> error(ResultCode resultCode) {
        return new Result<String>(resultCode);
    }

    public static Result<String> error(String msg) {
        return new Result<String>(msg);
    }

}